<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/9/1
 * Time: 17:58
 */
namespace app\shop\controller;
use think\Db;
use think\Request;
class My extends Base
{
    public function index(){
        if(Request::instance()->isAjax()){
            $user_image = input('param.user_image');//头像
            $user_username = input('param.user_username');//昵称
            $user_gender = input('param.user_gender');//1 男   2 女
            $user_phone = input('param.user_phone');//手机号码
            $user_gongsi = input('param.user_gongsi');//公司
            $user_zhiwu = input('param.user_zhiwu');//职务
            $user_real_name = input('param.user_real_name');//
            $user_qq = input('param.user_qq');//职务
            $user_grjj = input('param.user_grjj');//职务
            $user_email = input('param.user_email');//职务
            $data['user_image'] =$user_image;
            $data['user_username'] =$user_username;
            if($user_gender=='男'){
                $data['user_gender'] =1 ;
            }elseif ($user_gender=='女'){
                $data['user_gender'] =2 ;
            }elseif ($user_gender=='未知'){
                $data['user_gender'] = 3 ;
            }else{
                $data['user_gender'] = '' ;
            }
            $data['user_phone'] =$user_phone;
            $data['user_gongsi'] =$user_gongsi;
            $data['user_zhiwu'] =$user_zhiwu;
            $data['user_real_name'] =$user_real_name;
            $data['user_qq'] =$user_qq;
            $data['user_grjj'] =$user_grjj;
            $data['user_email'] =$user_email;
            $data['user_update_time'] =date('Y-m-d H:i:s');
            $info = Db::table('up_u_user')->where('user_id',session('user_id'))->update($data);
            if($info){
                return json(['status'=>200,'msg'=>'成功']);
            }else{
                return json(['status'=>100,'msg'=>'失败']);
            }
        }

        $user_id  = session('user_id');
        $field = 'user_email,user_image,user_username,user_gender,user_phone,user_gongsi,user_zhiwu,
                 user_real_name,user_qq,user_grjj';
        $res = Db::table('up_u_user')->where('user_id',$user_id)->field($field)->find();
        if($res['user_gender'] == 1){
            $res['sex'] = '男';
        }elseif ($res['user_gender'] == 2){
            $res['sex'] = '女';
        }elseif($res['user_gender'] == 3){
            $res['sex'] = '未知';
        }else{
            $res['sex'] = '';
        }
        $this->assign('res',$res);

        return $this->fetch();
    }
}